<template>

  <div>
    <el-button @click="openCheckIn()">办理入住</el-button>
    <el-tag>已经入住的客户信息</el-tag>
    <el-form ref="form"  label-width="80px" inline>
      <el-form-item label="顾客姓名">
        <el-input v-model="queryParam.customerName" placeholder="请输顾客姓名" ></el-input>
      </el-form-item>
      <el-form-item  >
        <el-button type="primary" size="mini" @click="search()">搜索</el-button>
      </el-form-item>
    </el-form>
    <el-table :data="tableData" style="width: 100%">
      <el-table-column align="center" type="index" label="序号" width="60">
      </el-table-column>

      <el-table-column prop="name" label="床位" align="center"></el-table-column>
      <el-table-column prop="customer_name" label="顾客姓名" align="center"></el-table-column>
      <el-table-column prop="checkin_date" label="入住日期" align="center"></el-table-column>
      <el-table-column prop="expiration_date" label="合同到期时间" align="center"></el-table-column>
      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <el-button type="waring" size="mini" @click="deleteById(scope.row.checkin_id)">删除</el-button>
        </template>

      </el-table-column>
    </el-table>

    <div class="block">
      <span class="demonstration"></span>
      <el-pagination
          @size-change="queryList"
          @current-change="queryList"
          :current-page.sync="queryParam.current"
          :page-size.sync="queryParam.size"
          :page-sizes="[5,10,15,20,50]"
          layout="total,sizes, prev, pager, next"
          :total="total">
      </el-pagination>
    </div>


    <el-dialog :visible.sync="visible">
           <CheckInEdit v-if="visible" @closeDialog="closeCheckIn"></CheckInEdit>
    </el-dialog>


  </div>

</template>

<script>
  import CheckInEdit  from "@/views/customer_manage/checkin/CheckInEdit";
  import service from "@/utils/request";



export default {
  components:{CheckInEdit},
  data() {
    return {
      visible:false,
      tableData: [],
      loading: false,
      form:{
        customerId:'',
        customerName:'',
        customerAge:'',
        customerSex:'',
        roomNumber:'',
        buildingId:'',
        elderType:'',
        foodlike:'',
        foodremarks:'',
        checkinDate:'',
        foodattention:'',
        expirationDate:'',
        attention:'',
        psychosomaticState:'',
        height:'',
        maritalStatus:'',
        weight:'',
        bloodType:'',
        idcard:'',
        contactTel:'',
        birthday:'',
      },
      total:0,
      pages:0,
      queryParam:{
        current:1,
        size:5,
        customerName:'',
        // customerAge:'',
        // customerSex:''
      }
    }
  },

  methods:{
    search(){
      this.queryParam.current=1;
      this.queryList();
      console.log("------------------------",this.params)
    },
    queryList() {
      this.loading = true;
      service.post("/checkin/list",this.queryParam).then((res) => {
        this.tableData = res.records;
        this.total = res.total;
        console.log("tableData:" ,this.tableData)
        console.log("total:" ,this.total)
        this.pages = res.pages;
        this.loading = false
      }).catch((error) => {
        // 添加错误处理逻辑
        console.error("An error occurred:", error);
        this.loading = false;
      });
    },
    openCheckIn(){
      this.visible = true;
    },
    closeCheckIn(){
      this.visible = false;
    },
    deleteById(id){
      this.$confirm('是否删除', '确认信息') .then(() => {
        service.get("/checkin/removeById/"+id).then((res) => {
          const success = res
          if(success){
            this.$message.success("删除成功");
            this.queryList();
          }
        })
      });
    },
  },
  created() {
    this.queryList()
  }
}
</script>

<style scoped>


</style>